package com.ljfiction.book.activitys;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ljfiction.book.MyView.SuperButton;
import com.ljfiction.book.R;
import com.ljfiction.book.http.HttpManager;
import com.ljfiction.book.tools.SettingManager;
import com.ljfiction.book.tools.StringTool;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class FeedbackActivity extends BaseActivity {

    @BindView(R.id.feedtext)
    EditText feedtext;
    @BindView(R.id.numtext)
    TextView numtext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        ButterKnife.bind(this);
        intView();
    }

    private void intView() {
        feedtext.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                numtext.setText(feedtext.getText().length() + "/" + 500);
            }
        });
    }

    @OnClick({R.id.backfeedback, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.backfeedback:
                goBack();
                break;
            case R.id.submit:
                if (StringTool.isEmpty(feedtext.getText())){
                    showToast("反馈意见不能为空哦！");
                }
                OkHttpUtils.post(HttpManager.IP + "/sys-EmailSend")

                        .params("sendEmail", "2177488142@qq.com")
                        .params("title", "意见反馈")
                        .params("content", feedtext.getText().toString())
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(String s, Call call, Response response) {
                            }
                        });
                showToast("提交成功");
                goBack();
                break;
        }
    }
}
